package cn.ichiva.puppet.example.base.p1;

import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.impl.AbstractPuppetComponent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;

import java.util.List;

/**
 *
 */
public class L3P1StyleClassComponent extends AbstractPuppetComponent {
    @FXML
    StringProperty message = new SimpleStringProperty("类型绑定");

    @FXML
    List<String> classList = FXCollections.observableArrayList();

    @Override
    public CharSequence render() {
        imports(VBox.class, Label.class, Button.class);
        return """
                <VBox>
                    <Label text="${message}" styleClass="${classList}" />
                    
                    <Button text="设置为红色" onAction="#setRed" />
                    <Button text="设置为黄色背景"  onAction="#yellowBackground" />
                    <Button text="设置为设置边框"  onAction="#setBorder" />
                </VBox>
                """;
    }

    @FXML
    public void setRed(){
        String red = "red";
        if(!classList.contains(red)){
            classList.add(red);
        }else {
            classList.remove(red);
        }
    }

    @FXML
    public void yellowBackground(){
        String red = "yellowBackground";
        if(!classList.contains(red)){
            classList.add(red);
        }else {
            classList.remove(red);
        }
    }
    @FXML
    public void setBorder(){
        String red = "redBorder";
        if(!classList.contains(red)){
            classList.add(red);
        }else {
            classList.remove(red);
        }
    }

}
